<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true"%>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>订单</title>
<link rel="stylesheet"
	href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
	<!-- 引入css样式文件 -->
	<!-- Bootstrap Core CSS -->
	<link href="<%=basePath%>css/bootstrap.min.css" rel="stylesheet" />
	<!-- MetisMenu CSS -->
	<link href="<%=basePath%>css/metisMenu.min.css" rel="stylesheet" />
	<!-- DataTables CSS -->
	<link href="<%=basePath%>css/dataTables.bootstrap.css" rel="stylesheet" />
	<!-- Custom CSS -->
	<link href="<%=basePath%>css/sb-admin-2.css" rel="stylesheet" />
	<!-- Custom Fonts -->
	<link href="<%=basePath%>css/font-awesome.min.css" rel="stylesheet" type="text/css" />
	<link href="<%=basePath%>css/boot-crm.css" rel="stylesheet" type="text/css" />
<style>
body {
	padding-top: 20px;
}

.table thead {
	background-color: #f5f5f5;
}
</style>
</head>
<body>
	<div class="panel panel-default">
		<div class="panel-heading">
			<h3 class="panel-title">添加订单</h3>
		</div>
		<div class="panel-body">
			<form method="post"
				action="${pageContext.request.contextPath}/order/add.action">
				<div class="form-group">
					<label for="orderId">订单号:</label> <input type="number"
						class="form-control" id="orderId" name="orderId">
				</div>
				<div class="form-group">
					<label for="userId">用户名:</label> <input type="number"
						class="form-control" id="userId" name="userId">
				</div>
				<div class="form-group">
					<label for="Date">日期:</label> <input type="date"
						class="form-control" id="Date" name="Date">
				</div>
				
				<button type="submit" class="btn btn-primary">提交</button>
			</form>
		</div>
	</div>
	<div id="page-wrapper">
		<div class="row">
			<div class="col-lg-12">
				<h1 class="page-header">订单查询</h1>
			</div>
			<!-- /.col-lg-12 -->
		</div>
		<!-- /.row -->
		<div class="panel panel-default">
			<div class="panel-body">
				<form class="form-inline" method="get"
					action="${pageContext.request.contextPath }/order/list.action">
					<button type="submit" class="btn btn-primary">查询所有订单</button>
				</form>
			</div>
		</div>
		<div class="row">
			<div class="col-lg-12">
				<div class="panel panel-default">
					<!-- /.panel-heading -->
					<table class="table table-bordered table-striped">
						<thead>
							<tr>
								<th>订单号</th>
								<th>用户名</th>
								<th>日期</th>
						
							</tr>
						</thead>
						<tbody>
							<c:forEach items="${page.rows}" var="row">
								<tr>
									<td>${row.orderid}</td>
									<td>${row.userid}</td>
									<td>${row.orderdate}</td>
									<td><a href="#" class="btn btn-primary btn-xs"
										data-toggle="modal" data-target="#orderEditDialog" onclick="editOrder(${row.orderid})">修改</a>
										<a href="#" class="btn btn-danger btn-xs"
										onclick="deleteOrder(${row.orderid})">删除</a></td>
								</tr>
							</c:forEach>
						</tbody>
					</table>
					
					<!-- /.panel-body -->
				</div>
				<!-- /.panel -->
			</div>
			<!-- /.col-lg-12 -->
		</div>
	</div>

<!-- 修改评论模态框 -->
<div class="modal fade" id="orderEditDialog" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="myModalLabel">修改</h4>
			</div>
			<div class="modal-body">
				<form id="editOrderForm" method="post">
						<div class="form-group">
					<label for="orderId">订单号:</label> <input type="number"
						class="form-control" id="orderId" name="orderId">
				</div>
						
						<div class="form-group">
					<label for="edituserId">用户名:</label> <input type="number"
						class="form-control" id="edituserId" name="edituserId">
				</div>
				<div class="form-group">
					<label for="editDate">日期:</label> <input type="date"
						class="form-control" id="editDate" name="editDate">
				</div>


					</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				<button type="button" class="btn btn-primary" onclick="updateOrder()">保存修改</button>
			</div>
		</div>
	</div>
</div>





	<!-- 引入js文件 -->
	<!-- jQuery -->
	<script src="<%=basePath%>js/jquery-1.11.3.min.js"></script>
	<!-- Bootstrap Core JavaScript -->
	<script src="<%=basePath%>js/bootstrap.min.js"></script>
	<!-- Metis Menu Plugin JavaScript -->
	<script src="<%=basePath%>js/metisMenu.min.js"></script>
	<!-- DataTables JavaScript -->
	<script src="<%=basePath%>js/jquery.dataTables.min.js"></script>
	<script src="<%=basePath%>js/dataTables.bootstrap.min.js"></script>
	<!-- Custom Theme JavaScript -->
	<script src="<%=basePath%>js/sb-admin-2.js"></script>
	<!-- 编写js代码 -->
	<script type="text/javascript">
	// 删除客户
	function deleteOrder(id) {
	    if(confirm('确实要删除该客户吗?')) {
	$.post("<%=basePath%>order/delete.action",{"id":id},
	function(data){
	            if(data =="OK"){
	                alert("评论删除成功！");
	                window.location.reload();
	            }else{
	                alert("评论删除成功！");
	                window.location.reload();
	            }
	        });
	    }
	}
	

    // 执行修改客户操作
	function updateOrder() {
		$.post("<%=basePath%>order/update.action",$("#editOrderForm").serialize(),function(data){
			if(data =="OK"){
				alert("评论信息更新成功！");
				window.location.reload();
			}else{
				alert("评论信息更新成功！");
				window.location.reload();
			}
		});
	}

	function editOrder(id) {
		var orderid=id;
	    
	    document.getElementById('orderId').value = orderid;
	}
    
	</script>
</body>
</html>
